package com.java.tutorials.jdk7.fileoperation;
import com.java.tutorials.Constants;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
/**
 * Created by xuzhike on 2016/1/25.
 * http://www.java2s.com/Code/Java/JDK-7/UnbufferedIOsupportintheFilesclass.htm
* Un-buffered IO support in the Files class
 */
public class UnbufferedIOsupportTest {
    public static void main(String[] args) throws IOException {
        Path file = Paths.get(Constants.TEST_PATH+Constants.TEST_EXISTING_FILE);
        Path newFile = Paths.get(Constants.TEST_PATH+"newUsers.txt");
        try (InputStream in = Files.newInputStream(file);
             OutputStream out = Files.newOutputStream(newFile,StandardOpenOption.CREATE,
                     StandardOpenOption.APPEND)) {
            int data = in.read();
            while (data != -1){
                out.write(data);
                data = in.read();
            }
        }

    }
}
